/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FRC2856.Robot;

import java.lang.*;
import com.sun.squawk.util.MathUtils;
import edu.wpi.first.wpilibj.Accelerometer;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.*;

/**
 *
 * @author asottile
 */
public class ProcessImage {
    public CustomCamera cam;
    
    protected double cameraSweepAngle = 0.9424777961; //radians; the angle of the camera's sweep.
    public final static int CLOCKWISE = 1; //1 if clockwise in drivetrain turn function is posative for clockwise; -1 if drivetrain turn functio is negative for clockwise
    
    public ProcessImage() //creation
    {
        cam = new CustomCamera(); //just save the camera
    }
    
    
    public Image getCameraImage(){
        try {
            return cam.camera.getImage();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    
    /**
     * Preconditions: the robot is approximately directly facing the lowest backboard, and an int for the hoop being aimed for
     * Postconditions: an array of doubles will be returned with the contents:
     * @0: the initial speed to shoot the ball at
     * @1: the degrees that the robot needs to turn to be facing the desired backboard.
     */
   public double[] getParameters(int desired, Aiming a){
        //Point[] coordinates = findPoints(getCameraImage()); //where the points are
        //int[] apparentDimensions = {(coordinates[0].x - coordinates[1].x + coordinates[3].x - coordinates[2].x)/2, (coordinates[0].y - coordinates[1].y + coordinates[3].y - coordinates[2].y)/2}; //the apparent height and width of the backboard
        ParticleAnalysisReport par = cam.getLowGoal(); //get the ParticleAnalysisReport on the lowest goal
        Point[] coordinates = {new Point(par.boundingRectTop, par.boundingRectLeft), new Point(par.boundingRectWidth+par.boundingRectLeft, par.boundingRectTop), new Point(par.boundingRectWidth+par.boundingRectLeft, par.boundingRectTop + par.boundingRectHeight), new Point(par.boundingRectLeft, par.boundingRectTop + par.boundingRectHeight)}; //where the points are
        int[] apparentDimensions = {par.boundingRectWidth, par.boundingRectHeight};
        double toTurn = 0; //the angle to turn that will be returned
        
        toTurn += ((coordinates[0].x + coordinates[1].x + coordinates[2].x + coordinates[0].x)/4 - (double)cam.camera.getResolution().width/2) * cameraSweepAngle; //account for a small difference from the exact center; this does not work exact so the camera needs to be pointed approximately toward the goal in the beginning anyway
        
        double distance = distance(apparentDimensions[1]) + Aiming.SHOOTER_AHEAD; //get the distance away from the lowest backboard
        
        double horizAngle = MathUtils.acos(Math.min((apparentDimensions[0]/Aiming.BACKBOARD_WIDTH)*(Aiming.BACKBOARD_HEIGHT/apparentDimensions[1]), 1)); //the horizontal angle form a line perpendicular to the wall
        int angularDirection = ((coordinates[0].y + coordinates[3].y)/2 < (coordinates[1].y + coordinates[2].y)/2)?-CLOCKWISE:CLOCKWISE; //get if you are on the 1 side of the court or the 2 side
        
        if(desired == 1 || desired == 2){ //if you are aiming for a side
            double wallAngle = Math.PI/2 - ((desired==2?-CLOCKWISE:CLOCKWISE)==angularDirection?-1:1) * horizAngle; //get the angle from center boards the robot is
            distance = Math.sqrt(distance * distance + Aiming.MID_DISPLACEMENT * Aiming.MID_DISPLACEMENT - 2 * distance * Aiming.MID_DISPLACEMENT * Math.cos(wallAngle)); //use law of cosines to get the new distance
            toTurn += (desired==2?CLOCKWISE:-CLOCKWISE) * MathUtils.asin(Math.sin(wallAngle)*Aiming.MID_DISPLACEMENT / distance); //use law of sines to get change in angle
        }
        
        double newDistance = Math.sqrt((Aiming.HOOP_DISPLACEMENT+Aiming.HOOP_RADIUS)*(Aiming.HOOP_DISPLACEMENT + Aiming.HOOP_RADIUS) + distance * distance - distance * (Aiming.HOOP_DISPLACEMENT + Aiming.HOOP_RADIUS) * Math.cos(horizAngle)); //use law of cosines to get the the distance to the center of hoop, not backboard
        toTurn += angularDirection * MathUtils.asin(Math.min(Math.sin(horizAngle) * (Aiming.HOOP_DISPLACEMENT + Aiming.HOOP_RADIUS) / newDistance, 1)); //use law of sines to get the angle the robot needs to turn from center of chosen backboard to center of hoop
        
        distance = newDistance - Aiming.SHOOTER_AHEAD; //update the distance variable to actual distance
        
        System.out.println(distance);
        double[] toReturn  = new double[1]; //make your conditions to return based on the table and toTurn
        
        toReturn[0] = conditions[(int)(distance*10)][desired]/10.0; //get your speed of launch
        
        toReturn[1] = toTurn;
        
        return toReturn;
    }
   
   /**
    * Preconditions: give it an image containing the lowest backboard in about the center
    * Postconditions: it will return the coordinates of the corners of the lowest backboard, f@0 = top left, @1 = top right @2 = bottom right @ 3 bottom left
    */
   public Point[] findPoints(Image i){
      return new Point[]{new Point(0, 0), new Point (10, 0), new Point (10, 10), new Point(0, 10)};
   }
   
    public double distance (double height)
    {
        double distance =  1.4808080808080808*((double)cam.camera.getResolution().height / height) * Aiming.BACKBOARD_HEIGHT; //the distance to the backboard as if you are looking strait on
        for(int i = 0; i < 5; i++){ //using the calculated distance as an approximation of the actual, estimate error and correct for that and repeat this 4 times
            double angle = MathUtils.atan((Aiming.HEIGHT[0] - Aiming.CAMERA_HEIGHT)/distance);
            height = Math.cos(angle) * height;
            distance =  1.4808080808080808*((double)cam.camera.getResolution().height / height) * Aiming.BACKBOARD_HEIGHT;
        }
        return distance; //return your (hopefully) fairly accurate distance
        
        //the distance computed is actually the hypotenuse, not x-distance
        //distance = Math.sqrt(distance * distance - backboardHeight * backboardHeight); //I think Valerie was wrong on the above comment
        
        //return distance; //return //why not just do a one-liner?
    }
    
    class Point{  
        int x, y;
        public Point(int X, int Y){
            x = X;
            y = Y;
        }
    }
    
    //Storing initial conditions
    /**conditions[distance][angle][@0 - initial velocity @1 - initial angle] */
    static short[][] conditions = new short[301][3]; 
    
    /**runs at start time, machine generated code to put values in conditions*/
    static
    {
        conditions[4][0] = 16;
        conditions[5][0] = 17;
        conditions[6][0] = 23;
        conditions[7][0] = 29;
        conditions[8][0] = 35;
        conditions[9][0] = 41;
        conditions[10][0] = 42;
        conditions[11][0] = 47;
        conditions[12][0] = 51;
        conditions[13][0] = 55;
        conditions[14][0] = 59;
        conditions[15][0] = 63;
        conditions[16][0] = 64;
        conditions[17][0] = 67;
        conditions[18][0] = 70;
        conditions[19][0] = 74;
        conditions[20][0] = 77;
        conditions[21][0] = 80;
        conditions[22][0] = 83;
        conditions[23][0] = 84;
        conditions[24][0] = 85;
        conditions[25][0] = 86;
        conditions[26][0] = 89;
        conditions[27][0] = 92;
        conditions[28][0] = 95;
        conditions[29][0] = 98;
        conditions[30][0] = 101;
        conditions[31][0] = 104;
        conditions[32][0] = 105;
        conditions[33][0] = 105;
        conditions[34][0] = 106;
        conditions[35][0] = 107;
        conditions[36][0] = 109;
        conditions[37][0] = 112;
        conditions[38][0] = 114;
        conditions[39][0] = 117;
        conditions[40][0] = 119;
        conditions[41][0] = 122;
        conditions[42][0] = 124;
        conditions[43][0] = 125;
        conditions[44][0] = 125;
        conditions[45][0] = 126;
        conditions[46][0] = 127;
        conditions[47][0] = 128;
        conditions[48][0] = 130;
        conditions[49][0] = 132;
        conditions[50][0] = 135;
        conditions[51][0] = 137;
        conditions[52][0] = 139;
        conditions[53][0] = 142;
        conditions[54][0] = 144;
        conditions[55][0] = 145;
        conditions[56][0] = 146;
        conditions[57][0] = 146;
        conditions[58][0] = 147;
        conditions[59][0] = 148;
        conditions[60][0] = 148;
        conditions[61][0] = 150;
        conditions[62][0] = 153;
        conditions[63][0] = 155;
        conditions[64][0] = 157;
        conditions[65][0] = 160;
        conditions[66][0] = 162;
        conditions[67][0] = 165;
        conditions[68][0] = 165;
        conditions[69][0] = 166;
        conditions[70][0] = 166;
        conditions[71][0] = 167;
        conditions[72][0] = 168;
        conditions[73][0] = 169;
        conditions[74][0] = 169;
        conditions[75][0] = 170;
        conditions[76][0] = 172;
        conditions[77][0] = 174;
        conditions[78][0] = 176;
        conditions[79][0] = 179;
        conditions[80][0] = 181;
        conditions[81][0] = 183;
        conditions[82][0] = 186;
        conditions[83][0] = 187;
        conditions[84][0] = 187;
        conditions[85][0] = 188;
        conditions[86][0] = 188;
        conditions[87][0] = 189;
        conditions[88][0] = 189;
        conditions[89][0] = 190;
        conditions[90][0] = 191;
        conditions[91][0] = 191;
        conditions[92][0] = 193;
        conditions[93][0] = 196;
        conditions[94][0] = 198;
        conditions[95][0] = 200;
        conditions[96][0] = 202;
        conditions[97][0] = 205;
        conditions[98][0] = 207;
        conditions[99][0] = 208;
        conditions[100][0] = 209;
        conditions[101][0] = 209;
        conditions[102][0] = 210;
        conditions[103][0] = 210;
        conditions[104][0] = 211;
        conditions[105][0] = 211;
        conditions[106][0] = 212;
        conditions[107][0] = 213;
        conditions[108][0] = 213;
        conditions[109][0] = 214;
        conditions[110][0] = 217;
        conditions[111][0] = 220;
        conditions[112][0] = 223;
        conditions[113][0] = 226;
        conditions[114][0] = 229;
        conditions[115][0] = 230;
        conditions[116][0] = 230;
        conditions[117][0] = 231;
        conditions[118][0] = 231;
        conditions[119][0] = 232;
        conditions[120][0] = 232;
        conditions[121][0] = 233;
        conditions[122][0] = 233;
        conditions[123][0] = 234;
        conditions[124][0] = 234;
        conditions[125][0] = 235;
        conditions[126][0] = 236;
        conditions[127][0] = 236;
        conditions[128][0] = 239;
        conditions[129][0] = 242;
        conditions[130][0] = 245;
        conditions[131][0] = 248;
        conditions[132][0] = 252;
        conditions[133][0] = 252;
        conditions[134][0] = 253;
        conditions[135][0] = 253;
        conditions[136][0] = 254;
        conditions[137][0] = 254;
        conditions[138][0] = 255;
        conditions[139][0] = 255;
        conditions[140][0] = 256;
        conditions[141][0] = 257;
        conditions[142][0] = 257;
        conditions[143][0] = 258;
        conditions[144][0] = 258;
        conditions[145][0] = 259;
        conditions[146][0] = 259;
        conditions[147][0] = 260;
        conditions[148][0] = 265;
        conditions[149][0] = 270;
        conditions[150][0] = 275;
        conditions[151][0] = 275;
        conditions[152][0] = 276;
        conditions[153][0] = 276;
        conditions[154][0] = 277;
        conditions[155][0] = 277;
        conditions[156][0] = 278;
        conditions[157][0] = 278;
        conditions[158][0] = 279;
        conditions[159][0] = 279;
        conditions[160][0] = 280;
        conditions[161][0] = 280;
        conditions[162][0] = 281;
        conditions[163][0] = 282;
        conditions[164][0] = 282;
        conditions[165][0] = 283;
        conditions[166][0] = 283;
        conditions[167][0] = 284;
        conditions[168][0] = 284;
        conditions[169][0] = 292;
        conditions[170][0] = 299;
        conditions[171][0] = 300;
        conditions[172][0] = 300;
        conditions[173][0] = 301;
        conditions[174][0] = 301;
        conditions[175][0] = 302;
        conditions[176][0] = 302;
        conditions[177][0] = 303;
        conditions[178][0] = 303;
        conditions[179][0] = 304;
        conditions[180][0] = 304;
        conditions[181][0] = 305;
        conditions[182][0] = 305;
        conditions[183][0] = 306;
        conditions[184][0] = 306;
        conditions[185][0] = 307;
        conditions[186][0] = 308;
        conditions[187][0] = 308;
        conditions[188][0] = 309;
        conditions[189][0] = 309;
        conditions[190][0] = 324;
        conditions[191][0] = 325;
        conditions[192][0] = 325;
        conditions[193][0] = 326;
        conditions[194][0] = 326;
        conditions[195][0] = 327;
        conditions[196][0] = 327;
        conditions[197][0] = 328;
        conditions[198][0] = 328;
        conditions[199][0] = 329;
        conditions[200][0] = 329;
        conditions[201][0] = 330;
        conditions[202][0] = 330;
        conditions[203][0] = 331;
        conditions[204][0] = 332;
        conditions[205][0] = 332;
        conditions[206][0] = 333;
        conditions[207][0] = 333;
        conditions[208][0] = 334;
        conditions[209][0] = 334;
        conditions[210][0] = 335;
        conditions[211][0] = 351;
        conditions[212][0] = 351;
        conditions[213][0] = 352;
        conditions[214][0] = 352;
        conditions[215][0] = 353;
        conditions[216][0] = 353;
        conditions[217][0] = 354;
        conditions[218][0] = 354;
        conditions[219][0] = 355;
        conditions[220][0] = 355;
        conditions[221][0] = 356;
        conditions[222][0] = 356;
        conditions[223][0] = 357;
        conditions[224][0] = 357;
        conditions[225][0] = 358;
        conditions[226][0] = 358;
        conditions[227][0] = 359;
        conditions[228][0] = 359;
        conditions[229][0] = 360;
        conditions[230][0] = 360;
        conditions[231][0] = 361;
        conditions[232][0] = 377;
        conditions[233][0] = 378;
        conditions[234][0] = 378;
        conditions[235][0] = 379;
        conditions[236][0] = 379;
        conditions[237][0] = 380;
        conditions[238][0] = 380;
        conditions[239][0] = 381;
        conditions[240][0] = 381;
        conditions[241][0] = 382;
        conditions[242][0] = 382;
        conditions[243][0] = 383;
        conditions[244][0] = 384;
        conditions[245][0] = 384;
        conditions[246][0] = 385;
        conditions[247][0] = 385;
        conditions[248][0] = 386;
        conditions[249][0] = 386;
        conditions[250][0] = 387;
        conditions[251][0] = 387;
        conditions[252][0] = 388;
        conditions[253][0] = 388;
        conditions[254][0] = 389;
        conditions[255][0] = 389;
        conditions[256][0] = 407;
        conditions[257][0] = 407;
        conditions[258][0] = 408;
        conditions[259][0] = 409;
        conditions[260][0] = 409;
        conditions[261][0] = 410;
        conditions[262][0] = 410;
        conditions[263][0] = 411;
        conditions[264][0] = 411;
        conditions[265][0] = 412;
        conditions[266][0] = 412;
        conditions[267][0] = 413;
        conditions[268][0] = 413;
        conditions[269][0] = 414;
        conditions[270][0] = 414;
        conditions[271][0] = 415;
        conditions[272][0] = 415;
        conditions[273][0] = 416;
        conditions[274][0] = 417;
        conditions[275][0] = 417;
        conditions[276][0] = 418;
        conditions[277][0] = 436;
        conditions[278][0] = 437;
        conditions[279][0] = 437;
        conditions[280][0] = 438;
        conditions[281][0] = 438;
        conditions[282][0] = 439;
        conditions[283][0] = 440;
        conditions[284][0] = 440;
        conditions[285][0] = 441;
        conditions[286][0] = 441;
        conditions[287][0] = 442;
        conditions[288][0] = 442;
        conditions[289][0] = 443;
        conditions[290][0] = 443;
        conditions[291][0] = 444;
        conditions[292][0] = 444;
        conditions[293][0] = 445;
        conditions[294][0] = 446;
        conditions[295][0] = 446;
        conditions[296][0] = 447;
        conditions[297][0] = 447;
        conditions[298][0] = 448;
        conditions[299][0] = 468;
        conditions[300][0] = 449;
        conditions[29][1] = 145;
        conditions[30][1] = 146;
        conditions[31][1] = 146;
        conditions[32][1] = 147;
        conditions[33][1] = 147;
        conditions[34][1] = 148;
        conditions[35][1] = 149;
        conditions[36][1] = 150;
        conditions[37][1] = 150;
        conditions[38][1] = 151;
        conditions[39][1] = 152;
        conditions[40][1] = 153;
        conditions[41][1] = 154;
        conditions[42][1] = 155;
        conditions[43][1] = 157;
        conditions[44][1] = 158;
        conditions[45][1] = 160;
        conditions[46][1] = 160;
        conditions[47][1] = 161;
        conditions[48][1] = 162;
        conditions[49][1] = 163;
        conditions[50][1] = 164;
        conditions[51][1] = 165;
        conditions[52][1] = 166;
        conditions[53][1] = 168;
        conditions[54][1] = 170;
        conditions[55][1] = 171;
        conditions[56][1] = 173;
        conditions[57][1] = 174;
        conditions[58][1] = 175;
        conditions[59][1] = 175;
        conditions[60][1] = 176;
        conditions[61][1] = 177;
        conditions[62][1] = 178;
        conditions[63][1] = 179;
        conditions[64][1] = 181;
        conditions[65][1] = 183;
        conditions[66][1] = 185;
        conditions[67][1] = 187;
        conditions[68][1] = 189;
        conditions[69][1] = 189;
        conditions[70][1] = 190;
        conditions[71][1] = 190;
        conditions[72][1] = 191;
        conditions[73][1] = 192;
        conditions[74][1] = 193;
        conditions[75][1] = 194;
        conditions[76][1] = 194;
        conditions[77][1] = 196;
        conditions[78][1] = 198;
        conditions[79][1] = 201;
        conditions[80][1] = 203;
        conditions[81][1] = 205;
        conditions[82][1] = 206;
        conditions[83][1] = 207;
        conditions[84][1] = 207;
        conditions[85][1] = 208;
        conditions[86][1] = 208;
        conditions[87][1] = 209;
        conditions[88][1] = 210;
        conditions[89][1] = 211;
        conditions[90][1] = 211;
        conditions[91][1] = 212;
        conditions[92][1] = 214;
        conditions[93][1] = 217;
        conditions[94][1] = 220;
        conditions[95][1] = 223;
        conditions[96][1] = 224;
        conditions[97][1] = 224;
        conditions[98][1] = 225;
        conditions[99][1] = 226;
        conditions[100][1] = 226;
        conditions[101][1] = 227;
        conditions[102][1] = 227;
        conditions[103][1] = 228;
        conditions[104][1] = 229;
        conditions[105][1] = 229;
        conditions[106][1] = 230;
        conditions[107][1] = 231;
        conditions[108][1] = 234;
        conditions[109][1] = 237;
        conditions[110][1] = 240;
        conditions[111][1] = 243;
        conditions[112][1] = 243;
        conditions[113][1] = 244;
        conditions[114][1] = 244;
        conditions[115][1] = 245;
        conditions[116][1] = 245;
        conditions[117][1] = 246;
        conditions[118][1] = 247;
        conditions[119][1] = 247;
        conditions[120][1] = 248;
        conditions[121][1] = 248;
        conditions[122][1] = 249;
        conditions[123][1] = 250;
        conditions[124][1] = 250;
        conditions[125][1] = 253;
        conditions[126][1] = 257;
        conditions[127][1] = 260;
        conditions[128][1] = 263;
        conditions[129][1] = 264;
        conditions[130][1] = 264;
        conditions[131][1] = 265;
        conditions[132][1] = 265;
        conditions[133][1] = 266;
        conditions[134][1] = 266;
        conditions[135][1] = 267;
        conditions[136][1] = 268;
        conditions[137][1] = 268;
        conditions[138][1] = 269;
        conditions[139][1] = 269;
        conditions[140][1] = 270;
        conditions[141][1] = 271;
        conditions[142][1] = 271;
        conditions[143][1] = 272;
        conditions[144][1] = 278;
        conditions[145][1] = 284;
        conditions[146][1] = 285;
        conditions[147][1] = 285;
        conditions[148][1] = 286;
        conditions[149][1] = 286;
        conditions[150][1] = 287;
        conditions[151][1] = 287;
        conditions[152][1] = 288;
        conditions[153][1] = 288;
        conditions[154][1] = 289;
        conditions[155][1] = 290;
        conditions[156][1] = 290;
        conditions[157][1] = 291;
        conditions[158][1] = 291;
        conditions[159][1] = 292;
        conditions[160][1] = 293;
        conditions[161][1] = 293;
        conditions[162][1] = 294;
        conditions[163][1] = 300;
        conditions[164][1] = 307;
        conditions[165][1] = 307;
        conditions[166][1] = 308;
        conditions[167][1] = 308;
        conditions[168][1] = 309;
        conditions[169][1] = 309;
        conditions[170][1] = 310;
        conditions[171][1] = 311;
        conditions[172][1] = 311;
        conditions[173][1] = 312;
        conditions[174][1] = 312;
        conditions[175][1] = 313;
        conditions[176][1] = 313;
        conditions[177][1] = 314;
        conditions[178][1] = 315;
        conditions[179][1] = 315;
        conditions[180][1] = 316;
        conditions[181][1] = 316;
        conditions[182][1] = 317;
        conditions[183][1] = 330;
        conditions[184][1] = 331;
        conditions[185][1] = 331;
        conditions[186][1] = 332;
        conditions[187][1] = 332;
        conditions[188][1] = 333;
        conditions[189][1] = 333;
        conditions[190][1] = 334;
        conditions[191][1] = 334;
        conditions[192][1] = 335;
        conditions[193][1] = 336;
        conditions[194][1] = 336;
        conditions[195][1] = 337;
        conditions[196][1] = 337;
        conditions[197][1] = 338;
        conditions[198][1] = 338;
        conditions[199][1] = 339;
        conditions[200][1] = 339;
        conditions[201][1] = 340;
        conditions[202][1] = 341;
        conditions[203][1] = 341;
        conditions[204][1] = 355;
        conditions[205][1] = 356;
        conditions[206][1] = 356;
        conditions[207][1] = 357;
        conditions[208][1] = 358;
        conditions[209][1] = 358;
        conditions[210][1] = 359;
        conditions[211][1] = 359;
        conditions[212][1] = 360;
        conditions[213][1] = 360;
        conditions[214][1] = 361;
        conditions[215][1] = 361;
        conditions[216][1] = 362;
        conditions[217][1] = 362;
        conditions[218][1] = 363;
        conditions[219][1] = 364;
        conditions[220][1] = 364;
        conditions[221][1] = 365;
        conditions[222][1] = 365;
        conditions[223][1] = 366;
        conditions[224][1] = 366;
        conditions[225][1] = 381;
        conditions[226][1] = 382;
        conditions[227][1] = 382;
        conditions[228][1] = 383;
        conditions[229][1] = 383;
        conditions[230][1] = 384;
        conditions[231][1] = 384;
        conditions[232][1] = 385;
        conditions[233][1] = 385;
        conditions[234][1] = 386;
        conditions[235][1] = 386;
        conditions[236][1] = 387;
        conditions[237][1] = 388;
        conditions[238][1] = 388;
        conditions[239][1] = 389;
        conditions[240][1] = 389;
        conditions[241][1] = 390;
        conditions[242][1] = 390;
        conditions[243][1] = 391;
        conditions[244][1] = 391;
        conditions[245][1] = 392;
        conditions[246][1] = 408;
        conditions[247][1] = 393;
        conditions[248][1] = 394;
        conditions[249][1] = 394;
        conditions[250][1] = 395;
        conditions[251][1] = 411;
        conditions[252][1] = 412;
        conditions[253][1] = 412;
        conditions[254][1] = 413;
        conditions[255][1] = 413;
        conditions[256][1] = 414;
        conditions[257][1] = 414;
        conditions[258][1] = 415;
        conditions[259][1] = 415;
        conditions[260][1] = 416;
        conditions[261][1] = 416;
        conditions[262][1] = 417;
        conditions[263][1] = 418;
        conditions[264][1] = 418;
        conditions[265][1] = 419;
        conditions[266][1] = 419;
        conditions[267][1] = 437;
        conditions[268][1] = 420;
        conditions[269][1] = 438;
        conditions[270][1] = 438;
        conditions[271][1] = 422;
        conditions[272][1] = 439;
        conditions[273][1] = 440;
        conditions[274][1] = 440;
        conditions[275][1] = 441;
        conditions[276][1] = 442;
        conditions[277][1] = 442;
        conditions[278][1] = 443;
        conditions[279][1] = 443;
        conditions[280][1] = 444;
        conditions[281][1] = 444;
        conditions[282][1] = 445;
        conditions[283][1] = 446;
        conditions[284][1] = 446;
        conditions[285][1] = 447;
        conditions[286][1] = 447;
        conditions[287][1] = 448;
        conditions[288][1] = 448;
        conditions[289][1] = 449;
        conditions[290][1] = 468;
        conditions[291][1] = 468;
        conditions[292][1] = 451;
        conditions[293][1] = 469;
        conditions[294][1] = 470;
        conditions[295][1] = 452;
        conditions[296][1] = 471;
        conditions[297][1] = 471;
        conditions[298][1] = 472;
        conditions[299][1] = 473;
        conditions[300][1] = 473;
        conditions[61][2] = 226;
        conditions[62][2] = 227;
        conditions[63][2] = 228;
        conditions[64][2] = 229;
        conditions[65][2] = 230;
        conditions[66][2] = 231;
        conditions[67][2] = 232;
        conditions[68][2] = 233;
        conditions[69][2] = 234;
        conditions[70][2] = 233;
        conditions[71][2] = 232;
        conditions[72][2] = 232;
        conditions[73][2] = 232;
        conditions[74][2] = 233;
        conditions[75][2] = 234;
        conditions[76][2] = 235;
        conditions[77][2] = 236;
        conditions[78][2] = 237;
        conditions[79][2] = 237;
        conditions[80][2] = 238;
        conditions[81][2] = 239;
        conditions[82][2] = 240;
        conditions[83][2] = 240;
        conditions[84][2] = 241;
        conditions[85][2] = 242;
        conditions[86][2] = 243;
        conditions[87][2] = 243;
        conditions[88][2] = 244;
        conditions[89][2] = 245;
        conditions[90][2] = 245;
        conditions[91][2] = 246;
        conditions[92][2] = 247;
        conditions[93][2] = 248;
        conditions[94][2] = 249;
        conditions[95][2] = 251;
        conditions[96][2] = 253;
        conditions[97][2] = 253;
        conditions[98][2] = 254;
        conditions[99][2] = 255;
        conditions[100][2] = 255;
        conditions[101][2] = 256;
        conditions[102][2] = 257;
        conditions[103][2] = 257;
        conditions[104][2] = 258;
        conditions[105][2] = 259;
        conditions[106][2] = 260;
        conditions[107][2] = 260;
        conditions[108][2] = 261;
        conditions[109][2] = 263;
        conditions[110][2] = 265;
        conditions[111][2] = 268;
        conditions[112][2] = 268;
        conditions[113][2] = 269;
        conditions[114][2] = 270;
        conditions[115][2] = 270;
        conditions[116][2] = 271;
        conditions[117][2] = 272;
        conditions[118][2] = 272;
        conditions[119][2] = 273;
        conditions[120][2] = 274;
        conditions[121][2] = 274;
        conditions[122][2] = 275;
        conditions[123][2] = 276;
        conditions[124][2] = 277;
        conditions[125][2] = 280;
        conditions[126][2] = 284;
        conditions[127][2] = 285;
        conditions[128][2] = 285;
        conditions[129][2] = 286;
        conditions[130][2] = 287;
        conditions[131][2] = 287;
        conditions[132][2] = 288;
        conditions[133][2] = 288;
        conditions[134][2] = 289;
        conditions[135][2] = 290;
        conditions[136][2] = 290;
        conditions[137][2] = 291;
        conditions[138][2] = 292;
        conditions[139][2] = 292;
        conditions[140][2] = 293;
        conditions[141][2] = 294;
        conditions[142][2] = 294;
        conditions[143][2] = 303;
        conditions[144][2] = 303;
        conditions[145][2] = 304;
        conditions[146][2] = 304;
        conditions[147][2] = 305;
        conditions[148][2] = 306;
        conditions[149][2] = 306;
        conditions[150][2] = 307;
        conditions[151][2] = 308;
        conditions[152][2] = 308;
        conditions[153][2] = 309;
        conditions[154][2] = 309;
        conditions[155][2] = 310;
        conditions[156][2] = 311;
        conditions[157][2] = 311;
        conditions[158][2] = 312;
        conditions[159][2] = 313;
        conditions[160][2] = 313;
        conditions[161][2] = 323;
        conditions[162][2] = 324;
        conditions[163][2] = 324;
        conditions[164][2] = 325;
        conditions[165][2] = 325;
        conditions[166][2] = 326;
        conditions[167][2] = 326;
        conditions[168][2] = 327;
        conditions[169][2] = 328;
        conditions[170][2] = 328;
        conditions[171][2] = 329;
        conditions[172][2] = 329;
        conditions[173][2] = 330;
        conditions[174][2] = 331;
        conditions[175][2] = 331;
        conditions[176][2] = 332;
        conditions[177][2] = 332;
        conditions[178][2] = 333;
        conditions[179][2] = 344;
        conditions[180][2] = 345;
        conditions[181][2] = 345;
        conditions[182][2] = 346;
        conditions[183][2] = 346;
        conditions[184][2] = 347;
        conditions[185][2] = 347;
        conditions[186][2] = 348;
        conditions[187][2] = 349;
        conditions[188][2] = 349;
        conditions[189][2] = 350;
        conditions[190][2] = 350;
        conditions[191][2] = 351;
        conditions[192][2] = 352;
        conditions[193][2] = 352;
        conditions[194][2] = 353;
        conditions[195][2] = 353;
        conditions[196][2] = 354;
        conditions[197][2] = 355;
        conditions[198][2] = 367;
        conditions[199][2] = 356;
        conditions[200][2] = 368;
        conditions[201][2] = 368;
        conditions[202][2] = 369;
        conditions[203][2] = 370;
        conditions[204][2] = 370;
        conditions[205][2] = 371;
        conditions[206][2] = 371;
        conditions[207][2] = 372;
        conditions[208][2] = 372;
        conditions[209][2] = 373;
        conditions[210][2] = 374;
        conditions[211][2] = 374;
        conditions[212][2] = 375;
        conditions[213][2] = 375;
        conditions[214][2] = 376;
        conditions[215][2] = 376;
        conditions[216][2] = 377;
        conditions[217][2] = 377;
        conditions[218][2] = 391;
        conditions[219][2] = 378;
        conditions[220][2] = 392;
        conditions[221][2] = 392;
        conditions[222][2] = 393;
        conditions[223][2] = 393;
        conditions[224][2] = 394;
        conditions[225][2] = 395;
        conditions[226][2] = 395;
        conditions[227][2] = 396;
        conditions[228][2] = 396;
        conditions[229][2] = 397;
        conditions[230][2] = 397;
        conditions[231][2] = 398;
        conditions[232][2] = 399;
        conditions[233][2] = 399;
        conditions[234][2] = 400;
        conditions[235][2] = 400;
        conditions[236][2] = 401;
        conditions[237][2] = 402;
        conditions[238][2] = 402;
        conditions[239][2] = 417;
        conditions[240][2] = 417;
        conditions[241][2] = 418;
        conditions[242][2] = 418;
        conditions[243][2] = 419;
        conditions[244][2] = 419;
        conditions[245][2] = 420;
        conditions[246][2] = 421;
        conditions[247][2] = 421;
        conditions[248][2] = 422;
        conditions[249][2] = 422;
        conditions[250][2] = 423;
        conditions[251][2] = 423;
        conditions[252][2] = 424;
        conditions[253][2] = 424;
        conditions[254][2] = 425;
        conditions[255][2] = 426;
        conditions[256][2] = 426;
        conditions[257][2] = 427;
        conditions[258][2] = 428;
        conditions[259][2] = 428;
        conditions[260][2] = 444;
        conditions[261][2] = 445;
        conditions[262][2] = 430;
        conditions[263][2] = 446;
        conditions[264][2] = 446;
        conditions[265][2] = 432;
        conditions[266][2] = 447;
        conditions[267][2] = 448;
        conditions[268][2] = 448;
        conditions[269][2] = 449;
        conditions[270][2] = 450;
        conditions[271][2] = 450;
        conditions[272][2] = 451;
        conditions[273][2] = 451;
        conditions[274][2] = 452;
        conditions[275][2] = 453;
        conditions[276][2] = 453;
        conditions[277][2] = 454;
        conditions[278][2] = 454;
        conditions[279][2] = 455;
        conditions[280][2] = 455;
        conditions[281][2] = 456;
        conditions[282][2] = 473;
        conditions[283][2] = 474;
        conditions[284][2] = 458;
        conditions[285][2] = 475;
        conditions[286][2] = 475;
        conditions[287][2] = 460;
        conditions[288][2] = 476;
        conditions[289][2] = 477;
        conditions[290][2] = 478;
        conditions[291][2] = 478;
        conditions[292][2] = 479;
        conditions[293][2] = 480;
        conditions[294][2] = 480;
        conditions[295][2] = 481;
        conditions[296][2] = 481;
        conditions[297][2] = 482;
        conditions[298][2] = 482;
        conditions[299][2] = 483;
        conditions[300][2] = 483;
    }
}